package sg.edu.nus.iss.ooad.jass.entity;

import java.io.Serializable;
import java.util.Collection;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Properties;

/**
 *
 * Response value object. This class is value object representing database table
 * Response. This class is intended to be used together with associated DAO object.
 * This class enscapsulates a particular Response.
 *
 * @author Isak Rabin (HT082193M)
 * @version 1.0
 * @since 1.0
 *
 * Development Environment : Netbeans IDE v6.7
 * Name of the File        : Response.java
 * Creation / Modification History
 *         Isak Rabin        20-Sep-2009        Created
 *
 */
public class Response implements IJASSEntity, Serializable {

        private static final long serialVersionUID = -6207639270428069803L;
        //Holds the attributes for Response Entity
        public static final String[] RESPONSE_ATTRIBUTES = {"ResponseID", "JobAdvertisementID", "JobSeekerID", "ResponseStatus", "ResponseDate"};
        /**
         * Persistent Instance variables.
         * This data is directly mapped to the columns of database table.
         */
        private String id = "";
        private String responseStatus = "";
        private String responseDate = "";
        private String jobadvertisementID = "";
        private String jobseekerID = "";

        /**
         * Default Contructor for Response class.
         */
        public Response() {
        }

        /**
         * Constructor of Response Class.
         * @param ID Response ID
         * @param name Response Name
         * @param jobadvertisementID JobAdvertisement ID.  
         * @param jobseekerID Jobseeker ID.
         */
        public Response(String id, String jobadvertisementID, String jobseekerID, String responseStatus, String responseDate) {
                this.id = id;
                this.jobadvertisementID = jobadvertisementID;
                this.jobseekerID = jobseekerID;
                this.responseStatus = responseStatus;
                this.responseDate = responseDate;
        }

        /**
         * Get the value of Id
         * @return the value of Id
         */
        public String getID() {
                return id;
        }

        /**
         * Set the value of Id
         *
         * @param Id new value of Id
         */
        public void setID(String id) {
                this.id = id;
        }

        /**
         * Get the value of responseStatus
         *
         * @return the value of responseStatus
         */
        public String getResponseStatus() {
                return responseStatus;
        }

        /**
         * Set the value of responseStatus
         *
         * @param responseStatus new value of responseStatus
         */
        public void setResponseStatus(String responseStatus) {
                this.responseStatus = responseStatus;
        }

        /**
         * Get the value of responseDate
         *
         * @return the value of responseDate
         */
        public String getResponseDate() {
                return responseDate;
        }

        /**
         * Set the value of responseDate
         *
         * @param responseDate new value of responseDate
         */
        public void setResponseDate(String responseDate) {
                this.responseDate = responseDate;
        }

        /**
         * Get the value of JobAdvertisement ID
         * @return the value of JobAdvertisement ID
         */
        public String getJobAdvertisementID() {
                return jobadvertisementID;
        }

        /**
         * Set the value of JobAdvertisement ID
         * @param jobdvertisement new value of JobAdvertisement ID
         */
        public void setJobAdvertisementID(String jobdvertisementID) {
                this.jobadvertisementID = jobdvertisementID;
        }

        /**
         * Get the value of Jobseeker ID
         * @return the value of Jobseeker ID
         */
        public String getJobseekerID() {
                return jobseekerID;
        }

        /**
         * Set the value of Jobseeker ID
         * @param jobseeker new value of Jobseeker ID
         */
        public void setJobseekerID(String jobseekerID) {
                this.jobseekerID = jobseekerID;
        }

        /**
         * Convert Properties into Response entity.
         * @param properties
         * @return
         */
        public Hashtable<String, IJASSEntity> fromJASSPropertiesFormat(Properties properties) {
                Hashtable<String, IJASSEntity> responses = new Hashtable<String, IJASSEntity>();

                String sTotalRecords = properties.getProperty("NumOfItems", "0");
                int iTotalRecords = Integer.parseInt(sTotalRecords);
                for (int i = 1; i <= iTotalRecords; i++) {
                        String[] values = new String[RESPONSE_ATTRIBUTES.length];
                        for (int j = 0; j < RESPONSE_ATTRIBUTES.length; j++) {
                                values[j] = properties.getProperty(RESPONSE_ATTRIBUTES[j] + String.valueOf(i));
                        }
                        Response response = new Response(values[0], values[1], values[2], values[3], values[4]);
                        responses.put(values[0], response);
                }

                return responses;
        }

        /**
         * Converts Responses entity to Properties Format.
         * @param collections
         * @return
         */
        public Properties toJassPropertiesFormat(Collection<IJASSEntity> collections) {
                Properties properties = new Properties();

                int count = 0;
                for (Iterator<IJASSEntity> i = collections.iterator(); i.hasNext();) {
                        count = count + 1;
                        Response response = (Response) i.next();
                        properties.setProperty(RESPONSE_ATTRIBUTES[0] + String.valueOf(count), response.getID());
                        properties.setProperty(RESPONSE_ATTRIBUTES[1] + String.valueOf(count), response.getJobAdvertisementID());
                        properties.setProperty(RESPONSE_ATTRIBUTES[2] + String.valueOf(count), response.getJobseekerID());
                        properties.setProperty(RESPONSE_ATTRIBUTES[3] + String.valueOf(count), response.getResponseDate());
                        properties.setProperty(RESPONSE_ATTRIBUTES[3] + String.valueOf(count), response.getResponseStatus());
                }
                properties.setProperty("NumOfItems", String.valueOf(collections.size()));

                return properties;
        }

        @Override
        public String toString() {
                return super.toString();
        }
}
